from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime


# 题目类别组
class Catogories_Base(BaseModel):
    name: str
    description: Optional[str]  # Text


class Catogories_Create(Catogories_Base):
    pass

class Catogories(Catogories_Create):
    id: int

    class Config:
        orm_mode = True

# 班级组
class Classes_Base(BaseModel):
    pass


class Classes_Create(Classes_Base):
    name: str


class Classes_Update(BaseModel):
    id: Optional[int]
    old_name: Optional[str]
    new_name: Optional[str]
    new_enabled: Optional[int]


class Classes(BaseModel):
    id: int
    enabled: int
    name: str

    class Config:
        orm_mode = True

# 用户组
class Users_Base(BaseModel):
    name: str = Field(None, description='用户名')
    number: str = Field(None, description='用户账号')
    sex: Optional[int] = Field(None, description='用户性别')


class Users_Create(Users_Base):
    password: str = Field(None, description='用户密码')


# 用户修改基本信息的可选参数：用户名、性别、密码
class User_Update(BaseModel):
    name: str = Field(None, description='用户名')
    sex: Optional[int] = Field(None, description='用户性别')
    password: Optional[str] = Field(None, description='用户密码')


class Users(Users_Create):
    id: int = Field(None, description='标识符')
    enabled: int = Field(None, description='是否启用')
    role: str = Field(None, description='角色')

    class Config:
        orm_mode = True


# 用户班级组
class User_Class_Base(BaseModel):
    pass

class User_Class_Create(User_Class_Base):
    number: str
    class_name: str


class User_Class(BaseModel):
    users_id: int
    classes_id: int
    id: int

    class Config:
        orm_mode = True


# 分数组
class Scores_Base(BaseModel):
    usual_score: float


class Scores_Create(Scores_Base):
    pass


class Scores(Scores_Create):
    id: int
    catogories_id: int
    users_id: int

    class Config:
        orm_mode = True


# 问题组
class Questions_Base(BaseModel):
    name: str
    description: Optional[str]  # Text


class Questions_Create(Questions_Base):
    pass

class Questions(Questions_Create):
    id: int
    questions_id: Optional[int]
    catogories_id: int

    class Config:
        orm_mode = True

# 测试组
class Tests_Base(BaseModel):
    submit_time: datetime
    correct_rate: float


class Tests_Create(Tests_Base):
    code: str  # Text


class Tests(Tests_Create):
    id: int
    users_id: int
    questions_id: int

    class Config:
        orm_mode: True

# 指导组
class Advisors_Base(BaseModel):
    pass


class Advisors_Create(Advisors_Base):
    pass


class Advisors(Advisors_Create):
    id: int
    users_id_user: int
    users_id_admin: int

    class Config:
        orm_mode: True


# 测试数据组
class Test_data_Base(BaseModel):
    input: str  # Text
    output: str  # Text


class Test_data_Create(Test_data_Base):
    pass


class Test_data(Test_data_Create):
    id: int
    questions_id: int
